package com.shengqi.xinnongren.work.ui.user.presenter;

import com.shengqi.xinnongren.common.base.BasePresenter;
import com.shengqi.xinnongren.common.config.network.Constants;
import com.shengqi.xinnongren.common.config.network.RetrofitHelper;
import com.shengqi.xinnongren.common.config.user.UserManager;
import com.shengqi.xinnongren.common.md5.SafeUtils;
import com.shengqi.xinnongren.work.ui.user.view.UpdatePwdView;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LuoYaWei on 2018/7/27.
 */
public class UpdatePwdPresenter extends BasePresenter<UpdatePwdView> {
    public void changePwd(String oldPwd, String newPwd) {
        Map<String, Object> map = new HashMap<>();
        map.put("oldPassWord", SafeUtils.getEncryptPwd(oldPwd));
        map.put("newPassWord", SafeUtils.getEncryptPwd(newPwd));
        JSONObject aesJsonData = Constants.getAESJsonData(map, UserManager.getInstance().getToken());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), aesJsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().updatePwd(requestBody), respond -> getView().showUpdatePwdRes(respond));
    }
}
